import React from "react";

import CommonRequestDataAction from "../common/CommonRequestDataAction";
import Constants from "../../common/Constants";

export default class UserRequestSelfDataAction extends CommonRequestDataAction {
  constructor() {
    super();

    this.moduleType = Constants.MODULE_TYPE.USER;
    this.name = "UserRequestSelfDataAction";

    this._callback = null;
  }

  finish(data, isSucceed, response, callback) {
    if (isSucceed) {
      Constants.USER = data;
      this.caller.setState({
        viewStatus: 3,
        userData: data,
        isResponeUpdate: true
      });
      this.onFinishSuccess(data, response, callback);
    } else if (response) {
      if (response.status == 401) {
        this._dealUnauthorized(this.caller);
      } else {
        this.caller.setState({ viewStatus: response.status });
      }
    } else {
      this.caller.setState({ viewStatus: 400 });
    }
  }

  onFinishSuccess(data, response, callback) {
    callback(data);
  }
}
